home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 15545 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: ix.netcom.com!netnews
  2. From: "John P. Atkinson" <jatk@ix.netcom.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: const member functions
  5. Date: Fri, 05 Apr 1996 14:09:06 -0800
  6. Organization: Data/Ware Development, Inc.
  7. Message-ID: <31659A02.7A9F@ix.netcom.com>
  8. References: <316588E6.7D61@geoplex.com>
  9. NNTP-Posting-Host: sdx-ca8-02.ix.netcom.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-NETCOM-Date: Fri Apr 05  2:09:34 PM PST 1996
  14. X-Mailer: Mozilla 2.0GoldB1 (Win95; I)
  15.  
  16. Jay B. Perry wrote:
  17. > The attached code doesn't compile, complaining about the non-const
  18. > object's attempt to use a non-const private method (even though a
  19. > const public method with the same name is available).
  20. > private:  //  Private methods
  21. >    //  Private accessor, should only be available to
  22. >    //  non-const X objects
  23. >    int& value( ) { return _value; }
  24.  
  25.  
  26. OK, looks like value is a private method only.  It's in scope only from within other methods of the 
  27. X class, or from any of X's friends (you've declared none, though.)
  28.  
  29.  
  30. >    //  The following line results in an error for several
  31. >    //  compilers, all complaining about an attempt to use
  32. >    //  the private X::value method!
  33. >    cout << t1.value() << endl;
  34.  
  35. So, you're calling value() from within main().  main() doesn't have scope to see into the private 
  36. portions of X.  value() shouldn't be callable from main(), irrespective of const vs non-const.
  37.  
  38. (I think!)
  39.  
  40. -- 
  41. --John Atkinson         Data/Ware Development, Inc.
  42.                         9449 Carroll Park Drive
  43.   jatk@ix.netcom.com    San Diego, CA   USA  92121   (619) 453-7660 ext.317
  44. "There is more to life than increasing its speed."
  45.   --Mahatma Gandhi
  46.